package com.course.android.ui.fragment;

import android.view.View;
import androidx.viewpager.widget.ViewPager;
import com.course.android.R;
import com.course.android.ui.adapter.HomePageAdaper;
import com.google.android.material.tabs.TabLayout;

public class HomeFragment extends BaseFragment{
    TabLayout tabLayout;
    HomePageAdaper pagerAdapter;

    @Override
    protected void initView(View view) {

        ViewPager viewPager=view.findViewById(R.id.fragmentcontainer);
        tabLayout=view.findViewById(R.id.include);
        pagerAdapter=new HomePageAdaper(getChildFragmentManager(),5);
        viewPager.setAdapter(pagerAdapter);
        tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                viewPager.setCurrentItem(tab.getPosition());
                pagerAdapter.notifyDataSetChanged();
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
        viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    }

    @Override
    protected void initEvent() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_home;
    }

    @Override
    protected void lazyLoad() {

    }
}
